﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RenShiKaoQin.Account
{
    public partial class EmployeeDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hrdbEntities ent = new hrdbEntities();

                var result = from emp in ent.TEmployees where emp.FEmployeeID.Equals(Page.User.Identity.Name) select emp;
                TEmployee employee = result.Single();
                TDept dept = employee.TDepts.OrderBy(p => p.FValidDate).Last();
                lbName.Text = employee.FName;
                var rdept = from tdept in ent.TDictDepts where tdept.FDeptCode.Equals(dept.FKQDeptCode) select tdept;
                try
                {
                    lbDept.Text = rdept.Single().FName;
                    lbDept.ID = rdept.Single().FDeptCode;
                    var rindept = from tindept in ent.TDictDepts where tindept.FDeptCode.Equals(dept.FDeptCode) select tindept;
                    lbInDept.Text = rindept.SingleOrDefault().FName;
                }
                catch
                {
                    Response.Write("您还没有所属科室或者考勤科室，请联系人事处");
                    Response.End();
                }
                lbGender.Text = employee.TDictGender != null ? employee.TDictGender.FName : "未知";
                if (employee.THeadShips.Any())
                {
                    THeadShip headShip = employee.THeadShips.OrderBy(p => p.FValidDate).Last();
                    lbHeadShip.Text = headShip.TDictHeadShip.FName;
                }
                else
                {
                    lbHeadShip.Text = "无";
                }

                if (employee.TTitles.Any())
                {
                    TTitle title = employee.TTitles.OrderBy(p => p.FValidDate).Last();
                    lbZhiChen.Text = title.TDictTitle.FName;
                }
                else
                {
                    lbZhiChen.Text = "无";
                }

                if (employee.TEngageJobs.Any())
                {
                    TEngageJob job = employee.TEngageJobs.OrderBy(p => p.FValidDate).Last();
                    lbGangWei.Text = job.TDictTitle.FName;
                }
                else
                {
                    lbGangWei.Text = "无";
                }
                lbTel.Text = employee.FMobileTel;

                lbBirthday.Text = String.Format("{0:D}", employee.FBirthday.Value);

                ent.Dispose();
            }
        }
    }
}